# -*-coding:Utf-8 -*
""" UI Box Class
"""
import bge, bgl, blf
from .zone import *
from .image import *
from .color import *


class Box(Zone):
	
	def __init__(self, parent,x, y, width, height, image = None):
		
		Zone.__init__(self, parent,x, y, width, height)
		self.background = image
		
	def destroy(self):
		Zone.destroy(self)
		self.background = None
		
	def _draw(self, x,y,alpha):
		Zone._draw(self,x,y,alpha)
		if self.background != None:
			bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.background.id)
			if alpha:
				bgl.glColor4f(1.0,1.0,1.0,self.getAlpha())
			bgl.glBegin(bgl.GL_QUADS)
			bgl.glTexCoord2f(0.0,0.0)
			bgl.glVertex2i(x, y)
			bgl.glTexCoord2f(0.0,1.0)
			bgl.glVertex2i(x, y+self.h)
			bgl.glTexCoord2f(1.0,1.0)
			bgl.glVertex2i(x+self.w, y+self.h)
			bgl.glTexCoord2f(1.0,0.0)
			bgl.glVertex2i(x+self.w, y)
			bgl.glEnd()
			bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)
